package com.qpx.zhoukao.message.controller;


import com.qpx.zhoukao.message.entity.MessageEntity;
import com.qpx.zhoukao.message.service.MessageService;
import com.zhoukao.dto.MessageDto;
import com.zhoukao.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class MessageController {

    @Autowired
    MessageService messageService;

    @RequestMapping("/message/save")
    public ResultEntity save(@RequestBody MessageDto messageDto){

        int mid = messageService.save(messageDto);
        return ResultEntity.ok("200","保存消息成功",mid);
    }


    @RequestMapping("/message/findMessageList")
    public ResultEntity findMessageList(MessageDto messageDto){
        Page<MessageEntity> messageList = messageService.findMessageList(messageDto);
        return ResultEntity.ok("200","查询成功",messageList);
    }

    @RequestMapping("/message/del")
    public ResultEntity delMessage(String ids){
        String[] split = ids.split(",");
        messageService.delMessage(Arrays.asList(split));
        return ResultEntity.ok();
    }
}
